home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.1 KB | 48 lines | [TEXT/CWIE] |
- // FiniteStackBase.cp
-
- #ifndef FiniteStackBase_h
- #include "FiniteStackBase.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- FiniteStackBase::FiniteStackBase( void *theStart,
- uint32 theLength,
- uint32 theElementSize )
- : start( static_cast<uint8 *>(theStart) ),
- end( static_cast<uint8 *>(theStart) + theLength * theElementSize ),
- elementSize( theElementSize ),
- allocateNext( static_cast<uint8 *>(theStart) )
- {
- Assert( CanMultiply( theLength, theElementSize ) )
- }
-
- void *FiniteStackBase::Allocate( uint32 size )
- {
- Assert( size == elementSize );
- Assert( !Full() );
-
- Assert( allocateNext >= start );
- Assert( ( allocateNext - start ) % elementSize == 0 );
-
- void *result = allocateNext;
-
- allocateNext += elementSize;
- Assert( allocateNext <= end );
-
- return result;
- }
-
- void FiniteStackBase::Release( void *p )
- {
- Assert( !IsEmpty() );
- Assert( p == allocateNext - elementSize );
-
- Assert( allocateNext <= end );
- Assert( ( allocateNext - start ) % elementSize == 0 );
-
- allocateNext -= elementSize;
- Assert( allocateNext >= start );
- }
-